package com.wltt.product.ahuthr.controller;

import com.wltt.product.ahuthr.model.ResultData;
import com.wltt.product.ahuthr.model.vo.ActivateReq;
import com.wltt.product.ahuthr.model.vo.LoginReq;
import com.wltt.product.ahuthr.model.vo.RegisterSystemUserReq;
import com.wltt.product.ahuthr.service.SystemUserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping(value = "/api/open")
public class SystemUserController {

    @Resource
    private SystemUserService systemUserService;

    /**
     * 注册
     *
     * @return
     */
    @PostMapping(value = {"/user/register"})
    public ResultData register(@RequestBody RegisterSystemUserReq registerSystemUserReq) throws NoSuchAlgorithmException {
        return systemUserService.register(registerSystemUserReq);
    }

    /**
     * 登录
     *
     * @return
     */
    @PostMapping(value = {"/user/login"})
    public ResultData login(HttpServletRequest request, @RequestBody LoginReq loginReq) throws NoSuchAlgorithmException {
        return systemUserService.login(request, loginReq);
    }

    /**
     * 获取当前登录人信息
     *
     * @return
     */
    @PostMapping(value = {"/user/currentUserInfo"})
    public ResultData currentUserInfo(HttpServletRequest request){
        return systemUserService.currentUserInfo(request);
    }

    /**
     * 登出
     *
     * @return
     */
    @PostMapping(value = {"/user/loginOut"})
    public ResultData loginOut(HttpServletRequest request) throws NoSuchAlgorithmException {
        return systemUserService.loginOut(request);
    }

    /**
     * 激活
     *
     * @return
     */
    @PostMapping(value = {"/user/activate"})
    public ResultData activate(HttpServletRequest request, @RequestBody ActivateReq activateReq) throws NoSuchAlgorithmException {
        return systemUserService.activate(request, activateReq);
    }
}
